package com.hsgene.gateway.support.filter;

import com.hsgene.common.ClientType;
import com.hsgene.common.util.result.ApiResult;
import com.hsgene.gateway.support.ClientRequestFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * 金琉璃请求过滤器
 *
 * @author wangbing
 * @version 1.0, 2018/11/9
 */
@Component
public class DoctorClientRequestFilter implements ClientRequestFilter {

    private final static Logger LOGGER = LoggerFactory.getLogger(DoctorClientRequestFilter.class);

    @Override
    public ClientType filterType() {
        return ClientType.GOLD_COLORED_GLASS;
    }

    @Override
    public int filterOrder() {
        return 5;
    }

    @Override
    public boolean shouldFilter(HttpServletRequest request) {
        return true;
    }

    @Override
    public ApiResult run(HttpServletRequest request) {
        // 校验金琉璃用户
        String userId = request.getParameter("userId");
        if (StringUtils.isEmpty(userId)) {
            userId = request.getParameter("doctorId");
        }
        LOGGER.info("金琉璃用户[{}]访问：{} {}", userId, request.getMethod(), request.getRequestURL());

        return ApiResult.succ();
    }
}
